package com.laamella.syntherface.synths.models;

public abstract class ParameterType {
	public final int minimum;
	public final int maximum;

	public abstract String format(int value);

	public ParameterType(int minimum, int maximum) {
		this.minimum = minimum;
		this.maximum = maximum;
	}

	public static class IntegerRange extends ParameterType {
		public IntegerRange(int minimum, int maximum) {
			super(minimum, maximum);
		}

		@Override public String format(int value) {
			return "" + value;
		}
	};

	public final static ParameterType Percentage = new ParameterType(0, 100) {
		@Override public String format(int value) {
			return "" + value + "%";
		}
	};
	public final static ParameterType PercentageAlsoNegative = new ParameterType(-100, 100) {
		@Override public String format(int value) {
			return "" + value + "%";
		}
	};

	public final static ParameterType Promillage = new ParameterType(0, 1000) {
		@Override public String format(int value) {
			return "" + value / 10.0 + "%";
		}
	};

	public final static ParameterType PromillageAlsoNegative = new ParameterType(-1000, 1000) {
		@Override public String format(int value) {
			return "" + value / 10.0 + "%";
		}
	};

	public static class Boolean extends ParameterType {
		private final String zero;
		private final String one;

		public Boolean(String zero, String one) {
			super(0, 1);
			this.zero = zero;
			this.one = one;
		}

		@Override public String format(int value) {
			return value == 0 ? zero : one;
		}
	};

	public final static ParameterType OnOff = new Boolean("on", "off");
	public final static ParameterType YesNo = new Boolean("yes", "no");

	public static class List extends ParameterType {
		private String[] items;

		@Override public String format(int value) {
			if (value < 0 || value >= items.length) {
				return "???";
			}
			return items[value];
		}

		public List(String[] items) {
			super(0, items.length - 1);
			this.items = items;
		}

		public List(String items) {
			this(items.split("\\s*,\\s*"));
		}
	}
}
